/**
 * 添加或者修改页面
 */
var HouseInfoInfoDlg = {
    data: {
        id: "",
        isDel: "",
        buildNo: "",
        unitNo: "",
        levelNo: "",
        doorNo: "",
        relXqId: "",
        createPerson: "",
        createDate: ""
    }
};

layui.use(['form', 'admin', 'ax', 'laydate', 'upload', 'formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;


    //渲染时间选择框
    var laydate = layui.laydate;
    laydate.render({
        elem: '#createDate' //指定元素
    });

    $.ajax(Feng.ctxPath + '/xqInfo/listAll', {
        success: function (res) {
            // console.log(res)
            $("#relXqId").empty();
            $("#relXqId").append("<option value=''>请选择小区</option>");
            for (let i = 0; i < res.length; i++) {
                $("#relXqId").append(new Option(res[i].xqName, res[i].id))
            }
            //重新渲染
            form.render("select");
        }
    })

    form.on('select(personType)', function (data) {
        if (data.value == "") {
            $("#personYzgxType").val("")
        } else if (data.value == 1) {
            $("#personYzgxType").val(1)
        } else if (data.value == 2) {
            $("#personYzgxType").val(2)
        }
        //重新渲染
        form.render("select");
    });


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/houseInfo/addItem", function (data) {
            Feng.success("添加成功！");
            window.location.href = Feng.ctxPath + '/houseInfo'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    $('#cancel').click(function () {
        window.location.href = Feng.ctxPath + '/houseInfo'
    });

});